package modelLag;
import java.util.ArrayList;

/**
 * Write a description of class LoanContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class LoanContainer{
    // instance variables - replace the example below with your own
    private static LoanContainer loanCon;
    private ArrayList<Loan> loanList;

    /**
     * Constructor for objects of class LoanContainer
     */
    private LoanContainer(){
        // initialise instance variables
        loanList = new ArrayList<Loan>();
    }

    public static LoanContainer getInstance(){
        if(loanCon ==null){
            loanCon = new LoanContainer();
        }
        return loanCon;
    }
    
    public void addLoan(Loan loan){
        loanList.add(loan);
    }
    public Loan findLoan(int serialNumber){
        int i=0;
        boolean found = false;
        Loan loan = null;
        while(i<loanList.size() && !found){
            Loan getLoan = loanList.get(i);
            int loanSerialNumber = getLoan.getSerialNumber();
            if (loanSerialNumber == serialNumber){
                found = true;
                loan = loanList.get(i);
                
            }
            else{
                i++;
            }
        }
        return loan;
    }
    public void updateLoan() {
        
    }
    public void deleteLoan(int serialNumber){
        int i = 0;
        boolean found = false;
        while(i < loanList.size() && !found){
            Loan getLoan = loanList.get(i);
            int loanSerialNumber = getLoan.getSerialNumber();
            if (loanSerialNumber == serialNumber){
                found = true;
            }
            else{
            i++;
            }
        }
        if(found){
            loanList.remove(i);
        }
    }
    public void printLoanList() {
        System.out.println("Loan Name:            Serial Number:");
        for (Loan loan : loanList) {
            System.out.println(loan.getLoanName()+"            "+loan.getSerialNumber()+"\n");
        }
    }
}